/*
 * FactorySimpeXML.cpp
 *
 *  Created on: 15.12.2012
 *      Author: caffeine
 */




#include "FactorySimpeXML.h"
#include <lampe/types.h>
#include <lampe/xml/IXMLFactoryEnvironment.h>
#include <lampe/xml/TFactorySimpeXML.h>

namespace lampe{
namespace xml{

	FactorySimpeXML::FactorySimpeXML(lampe::String element,XMLTagFactoryFunction function){
		tag=function;
		att=0;
		elementName=element;
	}
	FactorySimpeXML::FactorySimpeXML(lampe::String element,XMLAttribyteFactoryFunction function){
		tag=0;
		att=function;
		elementName=element;
	}

	FactorySimpeXML::~FactorySimpeXML(){
		//
	}

	lampe::xml::TagResult FactorySimpeXML::tagHandlerBefor(lampe::xml::IXMLFactoryEnvironment*environment,lampe::xml::IXmlNode*node){
		printf("run.....");
		if (!tag)
			return lampe::xml::NEXT;
		lampe::xml::TagResult res=tag(environment,node,true);
		printf("done!\n");
		return res;
	}
	lampe::xml::TagResult FactorySimpeXML::tagHandlerAfter(lampe::xml::IXMLFactoryEnvironment*environment,lampe::xml::IXmlNode*node){
		if (!tag)
			return lampe::xml::NEXT;
		return tag(environment,node,false);
	}
	lampe::xml::TagResult FactorySimpeXML::attributeHandler(lampe::xml::IXMLFactoryEnvironment*environment,lampe::xml::IXmlNode*node,lampe::u32 index){
		if (att)
			return att(environment,node,index);
		return lampe::xml::NEXT;
	}
	LAMPE_VECTOR_VENDOR<lampe::String> FactorySimpeXML::getProcessedTags(){
		if (!tag)
			return LAMPE_VECTOR_VENDOR<lampe::String>();
		LAMPE_VECTOR_VENDOR<lampe::String> list;
		list.push_back(elementName);
		return list;
	}
	LAMPE_VECTOR_VENDOR<lampe::String> FactorySimpeXML::getProcessedAttributes(){
		if (!att)
			return LAMPE_VECTOR_VENDOR<lampe::String>();
		LAMPE_VECTOR_VENDOR<lampe::String> list;
		list.push_back(elementName);
		return list;
	}
/*
void FactorySimpeXML::regSimpeTag(lampe::xml::IXMLFactoryEnvironment*environment,lampe::String element,XMLTagFactoryFunction function){
	if (!function)
		return;
	FactorySimpeXML*fs=new FactorySimpeXML(element,function);
	environment->registerHandler(fs);
	fs->drop();
}
void FactorySimpeXML::regSimpeAttribute(lampe::xml::IXMLFactoryEnvironment*environment,lampe::String element,XMLAttribyteFactoryFunction function){
	if (!function)
		return;
	FactorySimpeXML*fs=new FactorySimpeXML(element,function);
	environment->registerHandler(fs);
	fs->drop();
}
*/
}//namespace xml
}//namespace lampe
